package com.wd.mylibrary_login.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.graphics.blue
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import com.wd.mylibrary_base.base.BaseActivity
import com.wd.mylibrary_login.R
import com.wd.mylibrary_login.databinding.ActivityMessageBinding
import com.wd.mylibrary_login.fragment.ConstellationsFragment
import com.wd.mylibrary_login.fragment.LabelFragment
import com.wd.mylibrary_login.fragment.SexFragment
import com.wd.mylibrary_login.viewmodel.MessageViewModel

@Route(path = "/login/message")
class MessageActivity :BaseActivity<MessageViewModel,ActivityMessageBinding>(R.layout.activity_message){
    var  fragment= listOf(SexFragment(),ConstellationsFragment(),LabelFragment())
    override fun initView() {
       dataBinding.tab.addOnTabSelectedListener(object :OnTabSelectedListener{
           override fun onTabSelected(tab: TabLayout.Tab?) {
                  if(tab?.position==1){
                   dataBinding.tab.getTabAt(1)?.setIcon(R.mipmap.progressbar)
                  }
               if(tab?.position==2){
                   dataBinding.tab.getTabAt(2)?.setIcon(R.mipmap.progressbar)
                   dataBinding.tab.getTabAt(1)?.setIcon(R.mipmap.progressbar)
               }
           }

           override fun onTabUnselected(tab: TabLayout.Tab?) {
//               if(tab?.position==1){
//                   dataBinding.tab.getTabAt(1)
//               }
//               if(tab?.position==2){
//                   dataBinding.tab.getTabAt(2)
//                   dataBinding.tab.getTabAt(1)
//               }
           }

           override fun onTabReselected(tab: TabLayout.Tab?) {

           }

       })

    }

    override fun dataObserve() {
        dataBinding.vp.adapter= object : FragmentPagerAdapter(supportFragmentManager) {
            override fun getCount()=fragment.size

            override fun getItem(position: Int)=fragment[position]

        }
        dataBinding.vp.offscreenPageLimit=fragment.size-1
        dataBinding.tab.setupWithViewPager(dataBinding.vp)
        dataBinding.tab.getTabAt(0)?.setIcon(R.mipmap.progressbar)



    }

}